package com.example.smssenddemo;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnSend = (Button) findViewById(R.id.btn_send);
        EditText address = (EditText) findViewById(R.id.edit_adress);
        EditText content = (EditText) findViewById(R.id.edit_content);
        // API 23以上，对于比较重要的权限需要在JAVA代码中检查权限
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)
                != PackageManager.PERMISSION_GRANTED) {
            // Permission is not granted,Ask for permision
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 1);
        } else {// Permission has already been granted}
            btnSend.setOnClickListener(new SmsSendListener(this, address, content));
        }
    }
}
